from pages.basePage3 import BasePage
from config.setting import host_port
from selenium.webdriver.common.action_chains import ActionChains
import time

class Elment_Property(BasePage):
    def __init__(self):
        BasePage.__init__(self)
        self.driver.get(f"http://{host_port}/SharedParkingPlace/property/index.html")
    # 定位层

    def elment_yonghuguanli(self):
        return self.driver.find_element_by_xpath('//div[@id="main"]/div[1]/div[1]/div[1]/div[1]')

    # 定位物业方
    def elment_propert(self):
        return self.driver.find_element_by_xpath('//div[@id="_easyui_tree_5"]/span[3]')

    # 定位表单
    def elment_biaodan(self):
        a = self.driver.find_element_by_xpath('//div[@id="testIframe"]/div[2]/div[2]/div/iframe')
        return a
    # 定位增加按钮
    def elment_add(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[1]/span')
    #定位物业名
    def elment_name(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input1"]')
    # 定位电话
    def elment_phone(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input2"]')
    # 定位物业简介
    def elment_synopsis(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input3"]')
    # 定位物业证书
    def elment_zhenghsu(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input4"]')
    # 定位物业密码
    def elment_passwd(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input5"]')
    # 定位增加
    def elment_add_end(self):
        return self.driver.find_element_by_xpath('//div[@id="dlg-buttons"]/a[1]')
    # 定位下拉框
    def elment_chaxun_type(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/span/a/span')
    # 定位输入内容框
    def elment_input(self):
        return self.driver.find_element_by_id('_easyui_textbox_input6')
    # 定位查询按钮
    def elment_chaxun_end(self):
        return self.driver.find_element_by_xpath('//span[@class="textbox-addon textbox-addon-right"]')

# 定位捕获文本
    def elment_chaxun_text(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[2]/div[2]/table/tbody/tr/td[4]')
# 定位查询的文本
    def elment_cx_text(self):
        return self.driver.find_element_by_xpath('//tr[@id="datagrid-row-r1-2-0"]/td[2]/div')
# 定位要删除的物业信息
    def elment_xinxi(self):
        return self.driver.find_element_by_xpath('//tr[@id="datagrid-row-r1-2-1"]/td/div')
# 定位删除按钮
    def elment_delete(self):
        return self.driver.find_element_by_xpath('//div[@class="datagrid-toolbar"]/a[2]')



# 操作层
class Option_Property(Elment_Property):
    def __init__(self):
        Elment_Property.__init__(self)
    #     点击用户管理
    def click_yonghuguanli(self):
        self.elment_yonghuguanli().click()
    #     点击物业方
    def click_property(self):
        self.elment_propert().click()
#     切换表单
    def get_biaodan(self):
        a=self.elment_biaodan()
        return self.driver.switch_to.frame(a)
#     点击增加按钮
    def click_add(self):
        self.elment_add().click()
# 写入物业名
    def input_name(self,pname):
        return self.elment_name().send_keys(pname)
# 写入电话
    def input_phone(self,pphone):
        return self.elment_phone().send_keys(pphone)
# 写入简介
    def input_texts(self,pcontent):
        return self.elment_synopsis().send_keys(pcontent)
# 写入物业密码
    def input_passwd(self,ppasswd):
        return self.elment_passwd().send_keys(ppasswd)
#     写入物业证书
    def input_zhengshu(self,pzhengshu):
        return self.elment_zhenghsu().send_keys(pzhengshu)
#     点击增加
    def click_add_end(self):
        self.elment_add_end().click()
#   鼠标悬停在下拉框
    def xuanting(self):
        ActionChains(self.driver).move_to_element(self.elment_chaxun_type()).perform()  # 悬停
        time.sleep(1)
        return self.driver.find_element_by_xpath('//body[@class="panel-noscroll"]/div[5]/div[3]/div[1]').click()
#         输入查询电话
    def input_phones(self,cphone):
        return self.elment_input().send_keys(cphone)
# 点击查询
    def click_chaxun_end(self):
        return self.elment_chaxun_end().click()
#查询结果捕获
    def text_caxun(self):
        b=self.elment_chaxun_text().text
        return b
# 获取查询结果
    def cx_text(self):
        e=self.elment_cx_text().text
        return e
# 点击删除的物业信息
    def click_kuang(self):
        self.elment_xinxi().click()
# 点击删除按钮
    def cilck_delete(self):
        self.elment_delete().click()

# 业务层
class Apply_property(Option_Property):
    def __init__(self):
        Option_Property.__init__(self)
    def add_Apply(self,pname,pphone,pcontent,pzhengshu,ppasswd,cphone):
        '''

       :param pname: 物业名称
        :param pphone: 物业电话
        :param pcontent: 物业简介
        :param ppasswd: 物业密码
        :param cphone: 查询电话
        :return:
        '''

        self.click_yonghuguanli()
        self.click_property()
        self.get_biaodan()
        self.click_add()
        self.input_name(pname)
        self.input_phone(pphone)
        self.input_texts(pcontent)
        self.input_zhengshu(pzhengshu)
        self.input_passwd(ppasswd)
        self.click_add_end()
        self.xuanting()
        self.input_phones(cphone)
        self.click_chaxun_end()
        c=self.text_caxun()

        return c
    def chaxun_Apply(self,cphone):
        '''
    
        :param cphone: 查询电话号码
        :return: 
        '''
        self.click_yonghuguanli()
        self.click_property()
        self.get_biaodan()
        self.xuanting()
        self.input_phones(cphone)
        self.click_chaxun_end()
        d=self.cx_text()

        return d
    def delete_Apply(self,cphone):
        self.click_yonghuguanli()
        self.click_property()
        self.get_biaodan()
        self.click_kuang()
        self.cilck_delete()
        self.xuanting()
        self.input_phones(cphone)
        self.click_chaxun_end()
        d = self.cx_text()

        return d


if __name__ == '__main__':
    Apply_property().chaxun_Apply("13100871143")















